package freshmanspecial.mredrock.com.welcomefreshman.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import freshmanspecial.mredrock.com.welcomefreshman.Bean.BeautyInNearBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.CanteenBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.CateBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.DormitoryBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.LifeInNearBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.SchoolBuildingsBean;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by HP on 2017/8/10.
 */


public class StrategyRecyclerAdapter extends RecyclerView.Adapter<StrategyRecyclerAdapter.MyViewHolder> {
    private ArrayList<String> titleArrayList,contentArrayList,dizhiArrayList;
    private SchoolBuildingsBean schoolBuildingsBean;
    private DormitoryBean dormitoryBean;
    private CanteenBean canteenBean;
    private LifeInNearBean lifeInNearBean;
    private CateBean cateBean;
    private BeautyInNearBean beautyInNearBean;
    private Context context;
    private  int ScooldBulding=1,Canting=3,Qinshi=2,Shenghuo=6,Meishi=7,MeiJing=8;

    private int type;
    public StrategyRecyclerAdapter(Context context,Object object, int type) {
        this.context = context;
        this.type =type;

        if(type == ScooldBulding)
        {
            this.schoolBuildingsBean = (SchoolBuildingsBean) object;
        }
        if(type == Qinshi)
        {
            this.dormitoryBean = (DormitoryBean) object;
        }
        if(type == Canting)
        {
            this.canteenBean = (CanteenBean) object;
        }
        if(type == MeiJing)
        {
            this.beautyInNearBean = (BeautyInNearBean) object;
        }if(type == Meishi)
        {
            this.cateBean = (CateBean) object;
        }if(type == Shenghuo)
        {
            this.lifeInNearBean = (LifeInNearBean) object;
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(type==1 ||type==2||type==3)
        {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    context).inflate(R.layout.special_2017_strategy_recycler_item, parent,
                    false));
            return  holder;
        }else {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    context).inflate(R.layout.special_2017_stratety_zhoubian_item, parent,
                    false));
            return holder;

        }


    }

    @Override
    public void onBindViewHolder(StrategyRecyclerAdapter.MyViewHolder holder, int position) {
       if(type==1){
            holder.title.setText(schoolBuildingsBean.getData().get(position).getTitle());

            holder.content.setText(schoolBuildingsBean.getData().get(position).getContent());

            Glide.with(context).load(schoolBuildingsBean.getData().get(position).getUrl().get(0)).into(holder.imageView);
        }
        if(type==2){
            holder.title.setText(dormitoryBean.getData().get(position).getName());
            holder.content.setText(dormitoryBean.getData().get(position).getResume());
            Glide.with(context).load(dormitoryBean.getData().get(position).getUrl().get(0)).into(holder.imageView);
        }
        if(type==3){
            holder.title.setText(canteenBean.getData().get(position).getName());
            holder.content.setText(canteenBean.getData().get(position).getResume());
            Glide.with(context).load(canteenBean.getData().get(position).getUrl().get(0)).into(holder.imageView);
        }
        if(type==Shenghuo) {
           holder.zhoubian_jianjie.setText(lifeInNearBean.getData().get(position).getResume());
           holder.zhoubian_title.setText(lifeInNearBean.getData().get(position).getName());
           holder.zhoubian_dizhi.setText(lifeInNearBean.getData().get(position).getLocation());
           Glide.with(context).load(lifeInNearBean.getData().get(position).getUrl().get(0)).into(holder.zhoubian_image);
       }
        if(type==Meishi) {
            holder.zhoubian_jianjie.setText(cateBean.getData().get(position).getResume());
            holder.zhoubian_title.setText(cateBean.getData().get(position).getName());
            holder.zhoubian_dizhi.setText(cateBean.getData().get(position).getLocation());
            Glide.with(context).load(cateBean.getData().get(position).getUrl().get(0)).into(holder.zhoubian_image);        }
        if(type==MeiJing) {
            holder.zhoubian_jianjie.setText(beautyInNearBean.getData().get(position).getResume());
            holder.zhoubian_title.setText(beautyInNearBean.getData().get(position).getName());
            holder.zhoubian_dizhi.setText(beautyInNearBean.getData().get(position).getLocation());
            Glide.with(context).load(beautyInNearBean.getData().get(position).getUrl().get(0)).into(holder.zhoubian_image);        }
    }

    @Override
    public int getItemCount() {
        if(type==1)
        {
            return schoolBuildingsBean.getData().size();
        }else if (type==2)
        {
            return dormitoryBean.getData().size();

        }else if(type==3)
        {
            return canteenBean.getData().size();
        }else if(type==6)
        {
            return lifeInNearBean.getData().size();
        }else if(type==7)
        {
            return cateBean.getData().size();
        }else if(type==8)
        {
            return beautyInNearBean.getData().size();
        }
        return 0;
    }
    class MyViewHolder extends RecyclerView.ViewHolder
    {

        TextView content,title,zhoubian_title,zhoubian_dizhi,zhoubian_jianjie;
        ImageView imageView,zhoubian_image;
        public MyViewHolder(View view)
        {
            super(view);
            zhoubian_image = view.findViewById(R.id.zhoubian_image);
            content =  view.findViewById(R.id.content);
            imageView = view.findViewById(R.id.image_strategy);
            title = view.findViewById(R.id.text_title);
            zhoubian_title = view.findViewById(R.id.zhoubian_title);
            zhoubian_dizhi = view.findViewById(R.id.zhoubian_weizhi);
            zhoubian_jianjie = view.findViewById(R.id.zhoubian_jianjie);

        }
    }


}
